package com.cookiesoft.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cookiesoft.common.annotation.Log;
import com.cookiesoft.common.core.controller.BaseController;
import com.cookiesoft.common.core.domain.AjaxResult;
import com.cookiesoft.common.enums.BusinessType;
import com.cookiesoft.user.domain.ZhenUsers;
import com.cookiesoft.user.service.IZhenUsersService;
import com.cookiesoft.common.utils.poi.ExcelUtil;
import com.cookiesoft.common.core.page.TableDataInfo;

/**
 * 存储用户信息Controller
 *
 * @author anc
 * @date 2024-11-04
 */
@CrossOrigin
@RestController
@RequestMapping("/users/users" )
public class ZhenUsersController extends BaseController {
    @Autowired
    private IZhenUsersService zhenUsersService;

    /**
     * 查询存储用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('users:users:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(ZhenUsers zhenUsers) {
        startPage();
        List<ZhenUsers> list = zhenUsersService.selectZhenUsersList(zhenUsers);
        return getDataTable(list);
    }

    /**
     * 导出存储用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('users:users:export')" )
    @Log(title = "存储用户信息" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, ZhenUsers zhenUsers) {
        List<ZhenUsers> list = zhenUsersService.selectZhenUsersList(zhenUsers);
        ExcelUtil<ZhenUsers> util = new ExcelUtil<ZhenUsers>(ZhenUsers. class);
        util.exportExcel(response, list, "存储用户信息数据" );
    }

    /**
     * 获取存储用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('users:users:query')" )
    @GetMapping(value = "/{userId}" )
    public AjaxResult getInfo(@PathVariable("userId" ) Long userId) {
        return success(zhenUsersService.selectZhenUsersByUserId(userId));
    }

    /**
     * 新增存储用户信息
     */
    @PreAuthorize("@ss.hasPermi('users:users:add')" )
    @Log(title = "存储用户信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhenUsers zhenUsers) {
        return toAjax(zhenUsersService.insertZhenUsers(zhenUsers));
    }

    /**
     * 修改存储用户信息
     */
    @PreAuthorize("@ss.hasPermi('users:users:edit')" )
    @Log(title = "存储用户信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhenUsers zhenUsers) {
        return toAjax(zhenUsersService.updateZhenUsers(zhenUsers));
    }

    /**
     * 删除存储用户信息
     */
    @PreAuthorize("@ss.hasPermi('users:users:remove')" )
    @Log(title = "存储用户信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}" )
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return toAjax(zhenUsersService.deleteZhenUsersByUserIds(userIds));
    }
}